import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {Router} from "@angular/router";

@Component({
  selector: 'app-header-search',
  templateUrl: './header-search.component.html',
  styleUrls: ['./header-search.component.scss'],
})
export class HeaderSearchComponent implements OnInit {
  @Output() changeText: EventEmitter<string> = new EventEmitter<string>();
  timer: number;
  searchText: string;
  constructor(private route: Router,) { }

  ngOnInit() {
    this.searchText = '';
  }

  changeData(){
    if(!this.timer){
      // @ts-ignore
      this.timer = setTimeout(this.changeSearchText.bind(this), 1000);
    } else {
      this.timer = null;
    }
  }

  changeSearchText(){
    this.changeText.emit(this.searchText);
  }

  goToPage() {
    this.route.navigate([`/tabs/main`]).then();
  }

}
